package com.cdivtc.management.controller;

import com.cdivtc.management.pojo.Result;
import com.cdivtc.management.pojo.Student;
import com.cdivtc.management.pojo.TopicTitle;
import com.cdivtc.management.service.TeacherTopicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("api/teacherTopic")
public class TeacherTopicController {

    @Autowired
    private TeacherTopicService teacherTopicService;

    @RequestMapping("/add")
    public Result addTeacherTopic(TopicTitle topicTitle) {
        System.out.println("topicTitle = " + topicTitle == null);
        if (topicTitle.getTitle() != null) {
            TopicTitle topicTitle1 = teacherTopicService.addTopic(topicTitle);
            if (topicTitle != null) {
                return new Result().ok().addData(topicTitle);
            } else {
                return new Result().error("添加失败！！！");
            }
        } else {
            return new Result().error("数据为空");
        }
    }


    @RequestMapping("/update")
    public Result updateTeacherTopic(TopicTitle topicTitle) {
        System.out.println("topicTitle = " + topicTitle);
        if (topicTitle.getTitle() != null) {
            TopicTitle topicTitle1 = teacherTopicService.updateTopic(topicTitle);
            if (topicTitle1 != null) {
                return new Result().ok().addData(topicTitle1);
            } else {
                return new Result().error("更新失败！！！");
            }
        } else {
            return new Result().error("数据为空");
        }
    }

    @RequestMapping("/delete")
    public Result deleteTeacherTopic(TopicTitle topicTitle) {
        System.out.println("topicTitle = " + topicTitle);
        if (topicTitle.getId() != null) {
            TopicTitle topicTitle1 = teacherTopicService.deleteTopic(topicTitle);
            if (topicTitle1 != null) {
                return new Result().ok().addData(topicTitle1);
            } else {
                return new Result().error("删除失败！！！");
            }
        } else {
            return new Result().error("数据为空");
        }
    }

    @RequestMapping("/select")
    public Result selTeacherTopic(String str, String status, String teaId) {
        System.out.println("teaId = " + teaId);
        if (teaId != null) {
            List<TopicTitle> topicTitles = teacherTopicService.selTopic(str, status, teaId);
            return new Result().ok().addData(topicTitles);
        } else {
            return new Result().error("数据为空");
        }
    }


    @RequestMapping("/selectByCollege")
    public Result selectByCollege(Student stu) {
        System.out.println("TeacherTopicController line 80= " + stu);
        if (stu != null) {
            List<Map<String, Object>> list = teacherTopicService.selTeaTopic(stu);
            return new Result().ok().addData(list);
        } else {
            return new Result().error("数据为空");
        }
    }


}
